<?php
/**
 *
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2018/11/13 14:47
 * @copyright PanxSoft Inc.
 */

namespace App\Http\Controllers\Api\V1\App;


use App\Http\Controllers\ApiController;

use App\Http\Requests\Categories\CategoryCreateRequest;
use App\Models\Categories\Category;
use App\Services\Repositories\CategoryRepository;


class CategoryController extends ApiController
{
    private $categoryRepository;

    public function __construct(CategoryRepository $categoryRepository)
    {
        $this->categoryRepository = $categoryRepository;
    }

    /**
     * @param CategoryCreateRequest $request
     * @return array|\Illuminate\Http\Response
     */
    public function create(CategoryCreateRequest $request)
    {
        $categories = $this->categoryRepository->getCategories(
            $request->category_id,
            $request->type ?: Category::FILTER_TYPE_TOP
        );

        return $this->response(compact('categories'));
    }
}